using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Windows.Forms;

namespace _0712502_0712504_DesignPatternGame
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
            
        AutomatedTank1 comTank;
        

        TankBodyFactory tankBodyFactory;
      //  AutomatedTankFactory comTankFactory;
        UserControlledTankManager playerTankManager;
        MainGame mainGame;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            graphics.PreferredBackBufferHeight = GlobalVariables.SCREEN_HEIGHT;
            graphics.PreferredBackBufferWidth = GlobalVariables.SCREEN_WIDTH;

            System.Windows.Forms.Form f = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(this.Window.Handle);
            
            f.FormBorderStyle = FormBorderStyle.None;

            graphics.ApplyChanges();

            Content.RootDirectory = "Content";

           
        }
      
        protected override void Initialize()
        {
            this.IsMouseVisible = true;

           // comTankFactory = new AutomatedTankFactory();
            playerTankManager = new UserControlledTankManager();
            mainGame = new MainGame();
            base.Initialize();
        }
    
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            MyImageManager imageManager = new MyImageManager(this.Content);
            MySoundManager soundManager = new MySoundManager(this.Content);
            MyFontManager fontManager = new MyFontManager(this.Content);
            GameResourceContainer.InitGameResourceContainer(ref imageManager, ref soundManager, ref fontManager);

          //  comTankFactory.InitPrototypes();                        
          //  comTank = (AutomatedTank1) comTankFactory.CreateObject(1);
            mainGame.Initilize();         
           
        }

       
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
           // comTank.ISpeed = 1;
           // comTank.MovingDirection = MoveDirectionState.right;
           // comTank.Move();
            
          //  comTank.Update(gameTime);

            mainGame.UpdateGame(ref gameTime);
           
            base.Update(gameTime);
        }
     
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
        
            //comTank.DrawToScreen(gameTime, spriteBatch);
        
            mainGame.DrawToScreen(gameTime, spriteBatch);
            
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
